<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>CPP11ThreadPool: workstealingthreadpoolexecutor.hpp 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="CPP.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">CPP11ThreadPool
   </div>
   <div id="projectbrief">C++11线程池</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">workstealingthreadpoolexecutor.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef WorkStealingThreadPoolExecutor_H</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define WorkStealingThreadPoolExecutor_H</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;</div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;threadpoolexecutor.hpp&quot;</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;</div><div class="line"><a name="l00009"></a><span class="lineno"><a class="line" href="classWorkStealingThreadPoolExecutor.html">    9</a></span>&#160;<span class="keyword">class </span><a class="code" href="classWorkStealingThreadPoolExecutor.html">WorkStealingThreadPoolExecutor</a>: <span class="keyword">public</span> <a class="code" href="classThreadPoolExecutor.html">ThreadPoolExecutor</a> {</div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;    <span class="keyword">public</span>:</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;        <a class="code" href="classWorkStealingThreadPoolExecutor.html#a3e4e9fd05b5b325f2f051725410525cb">WorkStealingThreadPoolExecutor</a>(int32_t corePoolSize,</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;                                       int32_t maxPoolSize,</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;                                       <span class="keyword">const</span> std::vector&lt;<a class="code" href="classBlockingQueue.html">BlockingQueue&lt;Runnable::sptr&gt;</a>&gt;&amp; workQueue,</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;                                       <span class="keyword">const</span> <a class="code" href="classRejectedExecutionHandler.html">RejectedExecutionHandler</a>&amp; handler,</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;                                       <span class="keyword">const</span> std::string&amp; prefix = <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;        <a class="code" href="classWorkStealingThreadPoolExecutor.html#a3e4e9fd05b5b325f2f051725410525cb">WorkStealingThreadPoolExecutor</a>(int32_t corePoolSize,</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;                                       int32_t maxPoolSize,</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;                                       <span class="keyword">const</span> std::vector&lt;<a class="code" href="classBlockingQueue.html">BlockingQueue&lt;Runnable::sptr&gt;</a>&gt;&amp; workQueue,</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;                                       <a class="code" href="classRejectedExecutionHandler.html">RejectedExecutionHandler</a>* handler,</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;                                       <span class="keyword">const</span> std::string&amp; prefix = <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        <a class="code" href="classWorkStealingThreadPoolExecutor.html#a3e4e9fd05b5b325f2f051725410525cb">WorkStealingThreadPoolExecutor</a>(int32_t corePoolSize,</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;                                       int32_t maxPoolSize,</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;                                       <span class="keyword">const</span> std::string&amp; prefix = <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;        ~<a class="code" href="classWorkStealingThreadPoolExecutor.html">WorkStealingThreadPoolExecutor</a>() {}</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    <span class="keyword">public</span>:</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;        <span class="keyword">template</span>&lt;<span class="keyword">typename</span> F&gt;</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;        std::future&lt;typename std::result_of&lt;F()&gt;::type&gt;</div><div class="line"><a name="l00066"></a><span class="lineno"><a class="line" href="classWorkStealingThreadPoolExecutor.html#a7fa1b79c8be2b06a7952ccfd14aa7f6c">   66</a></span>&#160;        <a class="code" href="classWorkStealingThreadPoolExecutor.html#a7fa1b79c8be2b06a7952ccfd14aa7f6c">submit</a>(F f, <span class="keywordtype">bool</span> core = <span class="keyword">true</span>) {</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;            <span class="keyword">using</span> result_type = <span class="keyword">typename</span> std::result_of&lt;F()&gt;::type;</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;            std::packaged_task&lt;result_type()&gt; task(std::move(f));</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;            std::future&lt;result_type&gt; res(task.get_future());</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;            <span class="keywordflow">if</span>(<a class="code" href="classThreadPoolExecutor.html#aa4eb0971fc6f352df594186b6a118d6c">addWorker</a>(<a class="code" href="classRunnable.html">Runnable</a>(std::move(task)), core)) {</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;                <span class="keywordflow">return</span> res;</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;            } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;                <span class="keywordtype">int</span> c = <a class="code" href="classThreadPoolExecutor.html#a010113b7aac17ef364d417c485263873">ctl_</a>.load();</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;                <span class="keywordflow">if</span> (!<a class="code" href="classThreadPoolExecutor.html#a841ae2189d6f85b9df9f69dec5375341">isRunning</a>(c)) {</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;                    <a class="code" href="classThreadPoolExecutor.html#a14c4e3d786dcf22e858b11a95d2f77ef">reject</a>(<a class="code" href="classRunnable.html">Runnable</a>(std::move(task)));</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;                }</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;                <span class="keywordflow">return</span> res;</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;            }</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        }</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classWorkStealingThreadPoolExecutor.html#a962c0965822cd961984928ec26d61d4e">workerThread</a>(<span class="keywordtype">size_t</span> queueIdex) <span class="keyword">override</span>;</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classWorkStealingThreadPoolExecutor.html#a9a9ad791af26c0809a9e1864544930aa">coreWorkerThread</a>(<span class="keywordtype">size_t</span> queueIdex) <span class="keyword">override</span>;</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;};</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;</div><div class="line"><a name="l00096"></a><span class="lineno"><a class="line" href="classWorkStealingThreadPoolExecutor.html#a3e4e9fd05b5b325f2f051725410525cb">   96</a></span>&#160;<a class="code" href="classWorkStealingThreadPoolExecutor.html#a3e4e9fd05b5b325f2f051725410525cb">WorkStealingThreadPoolExecutor::WorkStealingThreadPoolExecutor</a>(int32_t corePoolSize,</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;        int32_t maxPoolSize,</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;        <span class="keyword">const</span> std::vector&lt;<a class="code" href="classBlockingQueue.html">BlockingQueue&lt;Runnable::sptr&gt;</a>&gt;&amp; workQueue,</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;        <span class="keyword">const</span> <a class="code" href="classRejectedExecutionHandler.html">RejectedExecutionHandler</a>&amp; handler,</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        <span class="keyword">const</span> std::string&amp; prefix)</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;    : <a class="code" href="classThreadPoolExecutor.html">ThreadPoolExecutor</a>(corePoolSize, maxPoolSize, workQueue, handler, prefix) {}</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;</div><div class="line"><a name="l00103"></a><span class="lineno"><a class="line" href="classWorkStealingThreadPoolExecutor.html#a80c8e32259e498cbb2c5625b272d37f3">  103</a></span>&#160;<a class="code" href="classWorkStealingThreadPoolExecutor.html#a3e4e9fd05b5b325f2f051725410525cb">WorkStealingThreadPoolExecutor::WorkStealingThreadPoolExecutor</a>(int32_t corePoolSize,</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;        int32_t maxPoolSize,</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;        <span class="keyword">const</span> std::vector&lt;<a class="code" href="classBlockingQueue.html">BlockingQueue&lt;Runnable::sptr&gt;</a>&gt;&amp; workQueue,</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;        <a class="code" href="classRejectedExecutionHandler.html">RejectedExecutionHandler</a>* handler,</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;        <span class="keyword">const</span> std::string&amp; prefix)</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;    : <a class="code" href="classThreadPoolExecutor.html">ThreadPoolExecutor</a>(corePoolSize, maxPoolSize, workQueue, handler, prefix) {}</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;</div><div class="line"><a name="l00110"></a><span class="lineno"><a class="line" href="classWorkStealingThreadPoolExecutor.html#adb702388a229cc2a0508901976dd9104">  110</a></span>&#160;<a class="code" href="classWorkStealingThreadPoolExecutor.html#a3e4e9fd05b5b325f2f051725410525cb">WorkStealingThreadPoolExecutor::WorkStealingThreadPoolExecutor</a>(int32_t corePoolSize,</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;        int32_t maxPoolSize,</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;        <span class="keyword">const</span> std::string&amp; prefix)</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;    : <a class="code" href="classThreadPoolExecutor.html">ThreadPoolExecutor</a>(corePoolSize, maxPoolSize, prefix) {}</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;</div><div class="line"><a name="l00115"></a><span class="lineno"><a class="line" href="classWorkStealingThreadPoolExecutor.html#a9a9ad791af26c0809a9e1864544930aa">  115</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="classWorkStealingThreadPoolExecutor.html#a9a9ad791af26c0809a9e1864544930aa">WorkStealingThreadPoolExecutor::coreWorkerThread</a>(<span class="keywordtype">size_t</span> queueIdex) {</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    setCurrentThreadName(<a class="code" href="classThreadPoolExecutor.html#acf28232c8314da96403992137fdd1c2f">prefix_</a>);</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;    <a class="code" href="classRunnable.html#abe8d3066c7305401d6f0aad8e70780f2">Runnable::sptr</a> task;</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;    std::unique_lock&lt;std::mutex&gt; lk(<a class="code" href="classThreadPoolExecutor.html#a2ef0eea2a8ca7a03bd9d361ced31f71b">mutex_</a>);</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;    <span class="keywordflow">while</span>(<a class="code" href="classThreadPoolExecutor.html#acdb626fdcb6ed4c7822508d1e0a3fcf5">runStateOf</a>(<a class="code" href="classThreadPoolExecutor.html#a010113b7aac17ef364d417c485263873">ctl_</a>.load()) &lt;= <a class="code" href="classThreadPoolExecutor.html#aa0958f2bf040bf2f199c629ec9145b44">SHUTDOWN</a>) {</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>[queueIdex].is_empty() &amp;&amp;</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;                <a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>[(queueIdex + 1) % <a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>.size()].is_empty()) {</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;            <a class="code" href="classThreadPoolExecutor.html#ad523af8548ca8f1dae80cb295ee567b3">notEmpty_</a>.wait(lk);</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;        }</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;        <span class="keywordflow">if</span>(<a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>[queueIdex].try_pop(task) ||</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;                <a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>[(queueIdex + 1) % <a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>.size()].try_pop(task)) {</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;            task-&gt;operator()();</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;        }</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    }</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;}</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;</div><div class="line"><a name="l00131"></a><span class="lineno"><a class="line" href="classWorkStealingThreadPoolExecutor.html#a962c0965822cd961984928ec26d61d4e">  131</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="classWorkStealingThreadPoolExecutor.html#a962c0965822cd961984928ec26d61d4e">WorkStealingThreadPoolExecutor::workerThread</a>(<span class="keywordtype">size_t</span> queueIdex) {</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    setCurrentThreadName(<a class="code" href="classThreadPoolExecutor.html#acf28232c8314da96403992137fdd1c2f">prefix_</a>);</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;    <a class="code" href="classRunnable.html#abe8d3066c7305401d6f0aad8e70780f2">Runnable::sptr</a> task;</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;    std::unique_lock&lt;std::mutex&gt; lk(<a class="code" href="classThreadPoolExecutor.html#a2ef0eea2a8ca7a03bd9d361ced31f71b">mutex_</a>);</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    <span class="keywordflow">while</span>(<a class="code" href="classThreadPoolExecutor.html#acdb626fdcb6ed4c7822508d1e0a3fcf5">runStateOf</a>(<a class="code" href="classThreadPoolExecutor.html#a010113b7aac17ef364d417c485263873">ctl_</a>.load()) &lt;= <a class="code" href="classThreadPoolExecutor.html#aa0958f2bf040bf2f199c629ec9145b44">SHUTDOWN</a>) {</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>[queueIdex].is_empty() &amp;&amp;</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;                <a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>[(queueIdex + 1) % <a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>.size()].is_empty()) {</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;            <a class="code" href="classThreadPoolExecutor.html#ad523af8548ca8f1dae80cb295ee567b3">notEmpty_</a>.wait(lk);</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;        }</div><div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;        <span class="keywordflow">if</span>(<a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>[queueIdex].try_pop(task) ||</div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;                <a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>[(queueIdex + 1) % <a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>.size()].try_pop(task)) {</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;            task-&gt;operator()();</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;        }</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;        <span class="keywordflow">if</span>(<a class="code" href="classThreadPoolExecutor.html#a2c8fc052c3760c89bf5198409d8c9c72">keepNonCoreThreadAlive_</a>) {</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;            std::this_thread::yield();</div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;        } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;            <span class="keywordflow">return</span>;</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;        }</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;    }</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;}</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/* WorkStealingThreadPoolExecutor_H */</span><span class="preprocessor"></span></div><div class="ttc" id="classThreadPoolExecutor_html_a415491f8f40c0fcb99e7ec25cdd209d0"><div class="ttname"><a href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">ThreadPoolExecutor::workQueues_</a></div><div class="ttdeci">std::vector&lt; BlockingQueue&lt; Runnable::sptr &gt; &gt; workQueues_</div><div class="ttdoc">任务队列 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:496</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a2ef0eea2a8ca7a03bd9d361ced31f71b"><div class="ttname"><a href="classThreadPoolExecutor.html#a2ef0eea2a8ca7a03bd9d361ced31f71b">ThreadPoolExecutor::mutex_</a></div><div class="ttdeci">std::mutex mutex_</div><div class="ttdoc">队列锁 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:488</div></div>
<div class="ttc" id="classWorkStealingThreadPoolExecutor_html_a962c0965822cd961984928ec26d61d4e"><div class="ttname"><a href="classWorkStealingThreadPoolExecutor.html#a962c0965822cd961984928ec26d61d4e">WorkStealingThreadPoolExecutor::workerThread</a></div><div class="ttdeci">virtual void workerThread(size_t queueIdex) override</div><div class="ttdoc">workerThread 核心工作线程 </div><div class="ttdef"><b>Definition:</b> workstealingthreadpoolexecutor.hpp:131</div></div>
<div class="ttc" id="classWorkStealingThreadPoolExecutor_html_a7fa1b79c8be2b06a7952ccfd14aa7f6c"><div class="ttname"><a href="classWorkStealingThreadPoolExecutor.html#a7fa1b79c8be2b06a7952ccfd14aa7f6c">WorkStealingThreadPoolExecutor::submit</a></div><div class="ttdeci">std::future&lt; typename std::result_of&lt; F()&gt;::type &gt; submit(F f, bool core=true)</div><div class="ttdoc">submit 在将来某个时候执行给定的任务, 任务可以在新线程或现有的合并的线程中执行, 可以有返回值,向任务队列提交的是任务副本 会抛出异常 </div><div class="ttdef"><b>Definition:</b> workstealingthreadpoolexecutor.hpp:66</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_acf28232c8314da96403992137fdd1c2f"><div class="ttname"><a href="classThreadPoolExecutor.html#acf28232c8314da96403992137fdd1c2f">ThreadPoolExecutor::prefix_</a></div><div class="ttdeci">std::string prefix_</div><div class="ttdoc">线程名前缀 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:482</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a841ae2189d6f85b9df9f69dec5375341"><div class="ttname"><a href="classThreadPoolExecutor.html#a841ae2189d6f85b9df9f69dec5375341">ThreadPoolExecutor::isRunning</a></div><div class="ttdeci">virtual bool isRunning(int c) const final</div><div class="ttdoc">isRunning 是否还在运行 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:399</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_ad523af8548ca8f1dae80cb295ee567b3"><div class="ttname"><a href="classThreadPoolExecutor.html#ad523af8548ca8f1dae80cb295ee567b3">ThreadPoolExecutor::notEmpty_</a></div><div class="ttdeci">std::condition_variable notEmpty_</div><div class="ttdoc">队列非空条件变量 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:492</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_aa0958f2bf040bf2f199c629ec9145b44"><div class="ttname"><a href="classThreadPoolExecutor.html#aa0958f2bf040bf2f199c629ec9145b44">ThreadPoolExecutor::SHUTDOWN</a></div><div class="ttdeci">const int32_t SHUTDOWN</div><div class="ttdoc">不再接受新任务 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:467</div></div>
<div class="ttc" id="classRejectedExecutionHandler_html"><div class="ttname"><a href="classRejectedExecutionHandler.html">RejectedExecutionHandler</a></div><div class="ttdoc">不再接受任务时的拒绝策略 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:15</div></div>
<div class="ttc" id="classWorkStealingThreadPoolExecutor_html_a3e4e9fd05b5b325f2f051725410525cb"><div class="ttname"><a href="classWorkStealingThreadPoolExecutor.html#a3e4e9fd05b5b325f2f051725410525cb">WorkStealingThreadPoolExecutor::WorkStealingThreadPoolExecutor</a></div><div class="ttdeci">WorkStealingThreadPoolExecutor(int32_t corePoolSize, int32_t maxPoolSize, const std::vector&lt; BlockingQueue&lt; Runnable::sptr &gt;&gt; &amp;workQueue, const RejectedExecutionHandler &amp;handler, const std::string &amp;prefix=&quot;&quot;)</div><div class="ttdoc">WorkStealingThreadPoolExecutor 构造函数 </div><div class="ttdef"><b>Definition:</b> workstealingthreadpoolexecutor.hpp:96</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a010113b7aac17ef364d417c485263873"><div class="ttname"><a href="classThreadPoolExecutor.html#a010113b7aac17ef364d417c485263873">ThreadPoolExecutor::ctl_</a></div><div class="ttdeci">std::atomic_int32_t ctl_</div><div class="ttdoc">控制变量 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:490</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_aa4eb0971fc6f352df594186b6a118d6c"><div class="ttname"><a href="classThreadPoolExecutor.html#aa4eb0971fc6f352df594186b6a118d6c">ThreadPoolExecutor::addWorker</a></div><div class="ttdeci">virtual bool addWorker(Runnable task, bool core=true)</div><div class="ttdoc">addWorker 将任务添加到队列 </div></div>
<div class="ttc" id="classRunnable_html_abe8d3066c7305401d6f0aad8e70780f2"><div class="ttname"><a href="classRunnable.html#abe8d3066c7305401d6f0aad8e70780f2">Runnable::sptr</a></div><div class="ttdeci">std::shared_ptr&lt; Runnable &gt; sptr</div><div class="ttdoc">std::shared_ptr&lt;Runnable&gt;别名 </div><div class="ttdef"><b>Definition:</b> runnable.hpp:18</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a2c8fc052c3760c89bf5198409d8c9c72"><div class="ttname"><a href="classThreadPoolExecutor.html#a2c8fc052c3760c89bf5198409d8c9c72">ThreadPoolExecutor::keepNonCoreThreadAlive_</a></div><div class="ttdeci">volatile bool keepNonCoreThreadAlive_</div><div class="ttdoc">是否允许非核心线程超时 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:484</div></div>
<div class="ttc" id="classThreadPoolExecutor_html"><div class="ttname"><a href="classThreadPoolExecutor.html">ThreadPoolExecutor</a></div><div class="ttdoc">线程池基本实现,每个线程都有一个任务队列 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:45</div></div>
<div class="ttc" id="classRunnable_html"><div class="ttname"><a href="classRunnable.html">Runnable</a></div><div class="ttdoc">Runnable interface 重写operator()或传进lambda </div><div class="ttdef"><b>Definition:</b> runnable.hpp:13</div></div>
<div class="ttc" id="classWorkStealingThreadPoolExecutor_html"><div class="ttname"><a href="classWorkStealingThreadPoolExecutor.html">WorkStealingThreadPoolExecutor</a></div><div class="ttdoc">任务窃取线程池,从下一个线程的任务队列窃取任务 </div><div class="ttdef"><b>Definition:</b> workstealingthreadpoolexecutor.hpp:9</div></div>
<div class="ttc" id="classBlockingQueue_html"><div class="ttname"><a href="classBlockingQueue.html">BlockingQueue</a></div><div class="ttdoc">BlockingQueue 阻塞队列(FIFO) </div><div class="ttdef"><b>Definition:</b> blockingqueue.hpp:14</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_acdb626fdcb6ed4c7822508d1e0a3fcf5"><div class="ttname"><a href="classThreadPoolExecutor.html#acdb626fdcb6ed4c7822508d1e0a3fcf5">ThreadPoolExecutor::runStateOf</a></div><div class="ttdeci">virtual int runStateOf(int32_t c) const final</div><div class="ttdoc">runStateOf 得到线程池状态 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:315</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a14c4e3d786dcf22e858b11a95d2f77ef"><div class="ttname"><a href="classThreadPoolExecutor.html#a14c4e3d786dcf22e858b11a95d2f77ef">ThreadPoolExecutor::reject</a></div><div class="ttdeci">virtual void reject(const Runnable &amp;command) final</div><div class="ttdoc">reject 将任务抛弃 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:292</div></div>
<div class="ttc" id="classWorkStealingThreadPoolExecutor_html_a9a9ad791af26c0809a9e1864544930aa"><div class="ttname"><a href="classWorkStealingThreadPoolExecutor.html#a9a9ad791af26c0809a9e1864544930aa">WorkStealingThreadPoolExecutor::coreWorkerThread</a></div><div class="ttdeci">virtual void coreWorkerThread(size_t queueIdex) override</div><div class="ttdoc">workerThread 非核心工作线程 </div><div class="ttdef"><b>Definition:</b> workstealingthreadpoolexecutor.hpp:115</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
